home *** CD-ROM | disk | FTP | other *** search
/ Adobe Digital Video Collection / Digital Video Collection CD.iso / After Effects 5.5 / MMScriptEng.Cab / F115577_dbspring.mm < prev    next >
Encoding:
Text File  |  2001-12-07  |  1.3 KB  |  38 lines

  1. // Springs - Version 1.3
  2.  
  3. // This script attaches a spring between the 2 layers shown in the popups.
  4. // The layers will continue along at the velocity they had at the
  5. // start of the work area.
  6.  
  7. //      LAYER                                               PROPERTY                     CHANNEL
  8. //      ------                                              ----------                     --------
  9. // 1: Layer attached to #2 by a spring        doesn't matter               doesn't matter
  10. // 2: Layer attached to #1 by a spring        doesn't matter               doesn't matter
  11.  
  12. if (time() == start_time) {
  13.     rest_length = 50;                    // Rest length of spring in pixels
  14.                                        //  change this to make the spring longer or shorter
  15.     damp = 0.95;                                // Damping (0 = infinite friction, 1 = none)
  16.  
  17.     p1 = value(pop_layer(1), position);
  18.     p2 = value(pop_layer(2), position);
  19.  
  20.     last_p1 = tmap(time() - step_time, value(pop_layer(1), position));
  21.     last_p2 = tmap(time() - step_time, value(pop_layer(2), position)); 
  22.  
  23.     v1 = (p1 - last_p1);
  24.     v2 = (p2 - last_p2);
  25. } else {
  26.     delta = p2 - p1;
  27.     n_delta = normalize(delta);
  28.  
  29.     a = n_delta * (length(delta) - rest_length) * step_time;
  30.  
  31.     v2 = (v2 - a) * damp;
  32.     v1 = (v1 + a) * damp;
  33.  
  34.     p1 = p1 + v1;
  35.     p2 = p2 + v2;
  36. }
  37. value(pop_layer(1), position) = p1;
  38. value(pop_layer(2), position) = p2;